﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.Core.DomainModel;
using System.Data.Linq;

namespace MethodWorx.Core.Linq
{
    public class LinqUnitOfWorkFactory : UnitOfWorkFactory
    {
        protected DataContext context;
        protected IRepositoryRegistry repositories;

        public LinqUnitOfWorkFactory(DataContext context, IRepositoryRegistry repositories)
        {
            this.context = context;
            this.repositories = repositories;
        }

        protected override IUnitOfWork CreateRootUnitOfWork()
        {
            return this.CreateLinqUnitOfWork(false);
        }

        protected override IUnitOfWork CreateInnerUnitOfWork(IUnitOfWork outerUnitOfWork)
        {
            return this.CreateLinqUnitOfWork(true);
        }

        protected virtual LinqUnitOfWork CreateLinqUnitOfWork(bool inner)
        {
            return new LinqUnitOfWork(this.context, this.repositories, inner);
        }
    }
}
